package com.ltxtiyu.video.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ltxtiyu.video.common.JsonTool;
import com.ltxtiyu.video.common.RetEnum;
import com.ltxtiyu.video.dao.ltx.MusicDao;
import com.ltxtiyu.video.entity.Music;
import com.ltxtiyu.video.service.ms.MusicService;
import com.ltxtiyu.video.vo.ms.UserVo;
import org.hashids.Hashids;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MusicServiceImpl implements MusicService {
    @Autowired
    private MusicDao musicDao;

    @Override
    public Map<String, Object> selectParamList(Map<String, Object> map) {
        List<Music> data= musicDao.findByParamList(map);
        int count = musicDao.findByParamCount(map);
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("msg","");
        result.put("count",count);
        result.put("data",data);
        return result;
    }

    @Override
    public void updateMusic(Music music) {

        musicDao.updateByPrimaryKeySelective(music);
    }

    @Override
    public String delByIds(String ids) {
        if (ids.contains(",")){
            String[] split = ids.split(",");
            for (int i = 0; i <split.length ; i++) {
                int id = Integer.parseInt(split[i]);
                musicDao.deleteByPrimaryKey(id);

            }
        }else {
            int id = Integer.parseInt(ids);
            musicDao.deleteByPrimaryKey(id);

        }
        return JsonTool.genJson(RetEnum.SUCCESS);
    }

    @Override
    public void addMusic(Music music) {
        music.setStatus(1);
        music.setCreateTime(new Date());
        musicDao.insertSelective(music);
    }
}
